#include<iostream>
#include<pthread.h>
#include<unistd.h>
using namespace std;
//新线程
void *ThreadRoutine(void*args)
{
    const char*threadname=(const char*)args;
    while(true)
    {
        cout<<"I am a new thread:"<<threadname<<"pid:"<<getpid()<<endl;
        sleep(1);
    }
}
int main()
{
    // 已经有进程了
    pthread_t tid;
    pthread_create(&tid,nullptr,ThreadRoutine,(void*)"thread 1");
    //主线程
    sleep(2);
     pthread_t tid1;
    pthread_create(&tid,nullptr,ThreadRoutine,(void*)"thread 2");
    sleep(2);
     pthread_t tid2;
    pthread_create(&tid,nullptr,ThreadRoutine,(void*)"thread 3");
    sleep(2);
     pthread_t tid3;
    pthread_create(&tid,nullptr,ThreadRoutine,(void*)"thread 4");
    while(true)
    {
        cout<<"I am main thread"<<"pid:"<<getpid()<<endl;
        sleep(1);
    }
    return 0;
}